export function isDate(date: any): boolean {
  return Object.prototype.toString.call(date) === '[object Date]'
}

export function isObject(object: any): boolean {
  return Object.prototype.toString.call(object) === '[object Object]'
}

// 对异步请求返回的responseHeaders做处理, 将其作为一个对象返回
export function parseResponseHeaders(headers: string): Object {
  let responseHeaders: any = {}

  if (!headers) {
    return responseHeaders
  }

  headers.split('\r\n').forEach((item, index) => {
    let [key, value] = item.split(':')
    key = key.trim().toLowerCase()
    if (!key) return
    responseHeaders[key] = value.trim()
  })
  return responseHeaders
}

// 将from实例和原型上的属性和方法拷贝到to上
export function extend<T, U>(to: T, from: U): T & U {
  for (const key in from) {
    // console.log(key);
    ;(<any>to)[key] = from[key]
  }
  return to as T & U
}
